package com.projet.qr;


import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * Created by yihui on 2017/4/3.
 */
public class QrCodePaddingTest {


    /**
     * 测试二维码
     */

    public static void testGenQrCode() {
        String content = "123123";

        // 简单的生成
        QrCodeConfig qrCodeConfig = QrCodeGenWrapper.createQrCodeConfig()
                .setMsg(content)
                .setH(300)
                .setW(300)
                .setPadding(0)
                .build();

        try {
            BufferedImage bufferedImage = QrCodeGenWrapper.asBufferedImage(qrCodeConfig);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ImageIO.write(bufferedImage, "png", out);
            Files.write(Paths.get("C:\\Users\\Administrator\\Desktop\\test\\" + System.currentTimeMillis() + ".png"), out.toByteArray());
            System.out.println("------------");
        } catch (Exception e) {
            System.out.println("create qrcode error! e: " + e);
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testGenQrCode();
    }

}
